using System.Data;
using Oracle.ManagedDataAccess.Client;

namespace ColorMapSystem.Helper;

public class OracleHelper
{
    private const string ConnectionString = "User Id=MESTK_ADMIN;Password=Ht_jYwK!AdmIn#M1;Data Source=10.20.5.18:1539/MESDB";

    public static DataTable ExecuteQuery(string sql, params OracleParameter[] parameters)
    {
        using var conn = new OracleConnection(ConnectionString);
        using var cmd = new OracleCommand(sql, conn);
        cmd.Parameters.AddRange(parameters);

        var table = new DataTable();
        using var adapter = new OracleDataAdapter(cmd);
        adapter.Fill(table);
        return table;
    }

    public static int ExecuteNonQuery(string sql, params OracleParameter[] parameters)
    {
        using var conn = new OracleConnection(ConnectionString);
        conn.Open();
        using var cmd = new OracleCommand(sql, conn);
        cmd.Parameters.AddRange(parameters);
        return cmd.ExecuteNonQuery();
    }

    public static object ExecuteScalar(string sql, params OracleParameter[] parameters)
    {
        using var conn = new OracleConnection(ConnectionString);
        conn.Open();
        using var cmd = new OracleCommand(sql, conn);
        cmd.Parameters.AddRange(parameters);
        return cmd.ExecuteScalar()!;
    }
}